package com.yxw.controller;

import com.yxw.pojo.User;
import com.yxw.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Slf4j
@RequestMapping("/users")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public MyResponse login(@RequestBody User user){
        User user1 = userService.getUserByUserCode(user);

        System.out.println(user.getUserPassword());

        if (user1 == null) {
            return new MyResponse(ResultCode.ERROR_LOGIN,null);
        }
        return new MyResponse(ResultCode.SUCCESS_LOGIN,user1);
    }
    @PostMapping("/lohout")
    public MyResponse logout(HttpSession session){




        return new MyResponse(ResultCode.SUCCESS_LOGOUT);
    }
}
